home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / os2 / octa209s.zip / octave-2.09 / src / ov-range.h < prev    next >
C/C++ Source or Header  |  1996-12-20  |  4KB  |  181 lines

  1. /*
  2.  
  3. Copyright (C) 1996 John W. Eaton
  4.  
  5. This file is part of Octave.
  6.  
  7. Octave is free software; you can redistribute it and/or modify it
  8. under the terms of the GNU General Public License as published by the
  9. Free Software Foundation; either version 2, or (at your option) any
  10. later version.
  11.  
  12. Octave is distributed in the hope that it will be useful, but WITHOUT
  13. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14. FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  15. for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with Octave; see the file COPYING.  If not, write to the Free
  19. Software Foundation, 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  20.  
  21. */
  22.  
  23. #if !defined (octave_range_h)
  24. #define octave_range_h 1
  25.  
  26. #if defined (__GNUG__)
  27. #pragma interface
  28. #endif
  29.  
  30. #include <cstdlib>
  31.  
  32. #include <string>
  33.  
  34. class ostream;
  35.  
  36. #include "Range.h"
  37.  
  38. #include "lo-utils.h"
  39. #include "mx-base.h"
  40. #include "oct-alloc.h"
  41. #include "str-vec.h"
  42.  
  43. #include "error.h"
  44. #include "mappers.h"
  45. #include "ov-base.h"
  46. #include "ov-typeinfo.h"
  47.  
  48. class Octave_map;
  49. class octave_value_list;
  50.  
  51. class tree_walker;
  52.  
  53. // Range values.
  54.  
  55. class
  56. octave_range : public octave_base_value
  57. {
  58. public:
  59.  
  60.   octave_range (void)
  61.     : octave_base_value () { }
  62.  
  63.   octave_range (double base, double limit, double inc)
  64.     : octave_base_value (), range (base, limit, inc)
  65.       {
  66.     if (range.nelem () < 0)
  67.       ::error ("invalid range");
  68.       }
  69.  
  70.   octave_range (const Range& r)
  71.     : octave_base_value (), range (r)
  72.       {
  73.     if (range.nelem () < 0)
  74.       ::error ("invalid range");
  75.       }
  76.  
  77.   octave_range (const octave_range& r)
  78.     : octave_base_value (), range (r.range) { }
  79.  
  80.   ~octave_range (void) { }
  81.  
  82.   octave_value *clone (void) { return new octave_range (*this); }
  83.  
  84.   void *operator new (size_t size)
  85.     { return allocator.alloc (size); }
  86.  
  87.   void operator delete (void *p, size_t size)
  88.     { allocator.free (p, size); }
  89.  
  90.   type_conv_fcn numeric_conversion_function (void) const;
  91.  
  92.   octave_value *try_narrowing_conversion (void);
  93.  
  94.   octave_value index (const octave_value_list& idx) const;
  95.  
  96.   idx_vector index_vector (void) const { return idx_vector (range); }
  97.  
  98.   int rows (void) const { return (columns () > 0); }
  99.   int columns (void) const { return range.nelem (); }
  100.  
  101.   bool is_defined (void) const { return true; }
  102.  
  103.   bool is_range (void) const { return true; }
  104.  
  105.   // XXX DO ME XXX
  106.   octave_value all (void) const;
  107.   octave_value any (void) const;
  108.  
  109.   bool is_real_type (void) const { return true; }
  110.  
  111.   bool valid_as_scalar_index (void) const
  112.     {
  113.       return (range.nelem () == 1
  114.           && ! xisnan (range.base ())
  115.           && NINT (range.base ()) == 1);
  116.     }
  117.  
  118.   bool valid_as_zero_index (void) const
  119.     {
  120.       return (range.nelem () == 1
  121.           && ! xisnan (range.base ())
  122.           && NINT (range.base ()) == 0);
  123.     }
  124.  
  125.   // XXX DO ME XXX
  126.   bool is_true (void) const;
  127.  
  128.   double double_value (bool) const;
  129.  
  130.   Matrix matrix_value (bool) const
  131.     { return range.matrix_value (); }
  132.  
  133.   Complex complex_value (bool) const;
  134.  
  135.   ComplexMatrix complex_matrix_value (bool) const
  136.     { return range.matrix_value (); }
  137.  
  138.   Range range_value (void) const { return range; }
  139.  
  140.   octave_value not (void) const;
  141.  
  142.   octave_value uminus (void) const { return octave_value (- range); }
  143.  
  144.   octave_value transpose (void) const;
  145.  
  146.   octave_value hermitian (void) const;
  147.  
  148.   octave_value convert_to_str (void) const;
  149.  
  150.   void print (ostream& os, bool pr_as_read_syntax = false);
  151.  
  152.   int type_id (void) const { return t_id; }
  153.  
  154.   string type_name (void) const { return t_name; }
  155.  
  156.   static int static_type_id (void) { return t_id; }
  157.  
  158.   static void register_type (void)
  159.     { t_id = octave_value_typeinfo::register_type (t_name); }
  160.  
  161. private:
  162.  
  163.   Range range;
  164.  
  165.   static octave_allocator allocator;
  166.  
  167.   // Type id of range objects, set by register_type ().
  168.   static int t_id;
  169.  
  170.   // Type name of scalar objects, defined in ov-range.cc.
  171.   static const string t_name;
  172. };
  173.  
  174. #endif
  175.  
  176. /*
  177. ;;; Local Variables: ***
  178. ;;; mode: C++ ***
  179. ;;; End: ***
  180. */
  181.